home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / New System Software Extensions / QuickDraw™ GX v1.0ß2 / Sample Code / Graphics Samples / bitmap shape with unique clip ƒ / bitmap w⁄unique clip.c next >
Encoding:
Text File  |  1993-09-14  |  5.8 KB  |  169 lines  |  [TEXT/KAHL]

  1. /*
  2.     bitmap w/unique clip.c
  3.     
  4.     This file demonstrates the ability of QuickDraw GX to clip any shape with any geometric shape. In this case, we
  5.     retrieve a bitmap shape from the resource fork of the application, and clip it with a text shape - "BEACH". We collect
  6.     both shapes into a GX picture, thereby allowing us to make one call to draw both shapes.
  7.     
  8.     NOTES:
  9.     • This file requires the following files to run correctly:
  10.         "graphics shell.c", "font library.c", "graphics debug library.c", "qd library.c", 
  11.         "color library.c", and "transform library.c".
  12.  
  13.     • For the best printing results, print this file in "landscape".
  14.     
  15.     ©1992 - 1993 Apple Computer, Inc.
  16.     All rights reserved.
  17. */
  18.  
  19. #include <events.h>
  20. #include <windows.h>
  21.  
  22. #include "Font library.h" 
  23. #include "graphics debugging.h"
  24. #include "graphics libraries.h"
  25. #include "graphics toolbox.h"
  26. #include "qd library.h"
  27. #include "graphics shell.h"
  28.  
  29. //
  30. //     Define "DEBUG" if you want validation of our bitmap shape when we read it in from the app's resource fork. Validation
  31. //    will only work with the "debugging" extension.  If you make the call without the "debugging" extension, you will just 
  32. //    return without any problems.
  33. //
  34. #define    DEBUG
  35.  
  36. /**  Set up the title and size of the window  **/
  37. Str255         gWindowTitle = "\p bitmap shape with unique clip ";
  38. Rect         gWindowQDRect  = {50, 20, 475, 475};
  39.  
  40. /** 
  41.     If gDebugging = TRUE, graphics library errors and notices will be posted.  This functionality  will only work with 
  42.     the "debugging" version of the QuickDraw GX init.  If this version of the init is not installed, nothing bad will happen, 
  43.     but these  functions will not work. 
  44. **/
  45. Boolean        gDebugging = true;
  46.  
  47.  
  48. /**  Set  "gGiveMeValidation" to TRUE, if you will receive run-time validation.  **/
  49. Boolean        gGiveMeValidation = true;
  50.  
  51.  
  52. /**     
  53.     gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  54.     in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  55.     With  gGraphicsHeapSize set to 25k, I had 2 free blocks left in the graphics gxHeap. Sounds good to me.
  56. **/
  57. long            gGraphicsHeapSize = 325;
  58.  
  59. gxShape         gthePicture;
  60.  
  61.  
  62. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  63.  
  64. void DoInitialization(gWindow)
  65. WindowPtr gWindow;
  66. {
  67.     gxShape        newClipShape;
  68.     gxShape        tempBitmapShape;
  69.     gxPoint        textPostion = {ff(1), ff(65)};
  70.  
  71.     InitCommonColors ();
  72.     
  73.     gthePicture = GXNewShape(gxPictureType);
  74.     GXSetShapeAttributes(gthePicture, gxUniqueItemsShape);
  75.  
  76.     //
  77.     //    Define the shape to clip our bitmap shape with. In this case, our clip shape will be a text shape which uses a 
  78.     //    text size of 96 point and the Helvetica font. We scale the sahpe up to fit the bitmap shape. The scaling could have
  79.     //    been perfomred by getting the bounds og the text and bitmap shape and scling for the difference. You can get
  80.     //    the bounds of both shapes by calling GXGetShapeBounds (...).
  81.     //
  82.     newClipShape = GXNewText(5,(unsigned char*)"BEACH", &textPostion);
  83.     SetShapeCommonFont(newClipShape, helveticaFont);
  84.     GXSetShapeTextSize(newClipShape, ff(96));
  85.     GXScaleShape(newClipShape, fl(1.20),  fl(3.50), 0, 0);
  86.     GXMoveShapeTo (newClipShape, ff(2), ff(1));
  87.  
  88.     //
  89.     //    Retrieve the bitmap shape form the resource fork of the application. With the "debugging" init installed, we
  90.     //    can check to see if the shape was retrieved correctly by calling the shape validation routine. If the shape is
  91.     //    not valid, we will recieve a warning in the debugger.
  92.     //
  93.     tempBitmapShape = GetPixMapShape(129);
  94.     
  95.     #ifdef DEBUG
  96.         GXValidateShape (tempBitmapShape);
  97.     #endif
  98.     
  99.     //
  100.     // Set the clip of our bitmap shape to our tesxt shape and add it to our picture.
  101.     //
  102.     GXSetShapeClip(tempBitmapShape, newClipShape);
  103.     GXMoveShape (tempBitmapShape, ff(5), ff(95));
  104.     GXSetPictureParts(gthePicture, 0, 0, 1, &tempBitmapShape, nil, nil, nil);
  105.  
  106.     //
  107.     //    Change the fill of our text shape be to the outline of the text, set the size used, set the pen to cruise on the outside
  108.     //    of the contour of each letter, and add it to our picture shape.
  109.     //
  110.     GXMoveShape (newClipShape, ff(5), ff(95));
  111.     GXSetShapeFill(newClipShape, gxClosedFrameFill);
  112.     GXSetShapeStyleAttributes(newClipShape, gxOutsideFrameStyle);
  113.     GXSetShapePen(newClipShape, ff(3));
  114.     SetShapeCommonColor(newClipShape, blue);
  115.  
  116.     GXSetPictureParts(gthePicture, 0, 0, 1, &newClipShape, nil, nil, nil);
  117.         
  118.     //
  119.     //    We no longer need the clip or bitmap shapes because they have been copied into the picture.
  120.     //
  121.     GXDisposeShape (newClipShape);
  122.     GXDisposeShape (tempBitmapShape);
  123. }
  124.  
  125.  
  126. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  127.  
  128. void DoDraw(gWindow)
  129. WindowPtr gWindow;
  130. {
  131.     GXDrawShape (gthePicture);
  132. }
  133.  
  134.  
  135. /*------ DoDispose -------------------------------------------------------------------------------------*/
  136.  
  137. void DoDispose(gWindow)
  138. WindowPtr gWindow;
  139. {
  140.     /**  
  141.         You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  142.         form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  143.         call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  144.         SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  145.         can turn notices on in this file by setting gDebugging = TRUE (above).
  146.     **/
  147.     DisposeCommonColors ();
  148.     GXDisposeShape(gthePicture);  
  149.      GXDisposeShape(gWindowBoundsShape);  
  150.     DisposeWindow(gWindow);
  151. }
  152.     
  153.  
  154.  
  155. /*------ DoClick ---------------------------------------------------------------------------------------*/
  156.  
  157. void DoClick(gWindow)
  158. WindowPtr gWindow;
  159. {
  160. }
  161.  
  162.  
  163. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  164.  
  165. void DoIdle(gWindow)
  166. WindowPtr gWindow;
  167. {
  168. }
  169.